package cn.lanqiao.system.service.impl;

import cn.lanqiao.common.entity.User;
import cn.lanqiao.system.mapper.UserMapper;
import cn.lanqiao.system.service.UserService;
import java.util.List;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

@Service
@Repository
public class UserServiceImp implements UserService {
    @Autowired
    private UserMapper usermapper;

    public UserServiceImp() {
    }

    public Integer UserRegister(User user) {
        return this.usermapper.insertSelective(user);
    }

    public int deleteByPrimaryKey(Integer userid) {
        return this.usermapper.deleteByPrimaryKey(userid);
    }
    @Override
    public int batchDeleteUser(Integer[] ids) {
        return usermapper.batchDeleteUser(ids);
    }

    public Integer updateUserInfo(User user) {
        return this.usermapper.updateUserInfo(user);
    }

    public List<User> findUserByName(String username) {
        return this.usermapper.findUserByName(username);
    }

    @Override
    public User login(String username, String password) {
        return usermapper.findUserByUserNameAndPassword(username,password);
    }
    @Override
    public PageInfo<User> getPage(int pageNo, int pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<User> list= usermapper.findAllUser();
        PageInfo<User> page=new PageInfo<>(list);
        return page;
    }

    @Override
    public PageInfo<User> getTypePage(int pageNo, int pageSize,Integer typeId) {

        PageHelper.startPage(pageNo,pageSize);
        List<User> list=usermapper.getTypeId(typeId);
        PageInfo<User> page2=new PageInfo<>(list);
        return page2;
    }
    @Override
    public int save(User user) {
        if(user.getId()==null){
            return usermapper.UserRegister(user);
        }else{
            return usermapper.updateUserInfo(user);
        }
    }
    @Override
    public User findById(Integer id) {
        return usermapper.findById(id);
    }

    @Override
    public User getUserById(Integer id) {
        return usermapper.getUserById(id);
    }

    @Override
    public Integer updateUserById(User user) {
        return usermapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public Integer insertSelective(User record) {
        return usermapper.insertSelective(record);
    }
}
